// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
    future: {
        compatibilityVersion: 4,
    },
    srcDir: 'app/',
    serverDir: "server/",
    dir: {
        app: 'app'
    },
    logLevel: process.env.NODE_ENV !== 'production' ? 'info' : 'silent',
    router: {
        options: {
            hashMode: false,
            scrollBehaviorType: 'smooth'
        }
    },
    experimental: {
        restoreState: true,
        inlineRouteRules: true,
        scanPageMeta: true,
        sharedPrerenderData: true,
        renderJsonPayloads: true
    },
    app: {
        head: {
            charset: 'UTF-8',
            viewport: 'width=device-width, initial-scale=1'
        }
        ,
        pageTransition: {
            name: 'fade',
            mode: 'out-in'
        }
        ,
        layoutTransition: {
            name: 'slide',
            mode: 'out-in'
        }
    },
    ssr: !process.env.SSR,
    compatibilityDate: '2024-04-03',
    devtools: {enabled: process.env.NODE_ENV !== 'production'},
    modules: [
        '@nuxtjs/i18n',
        '@pinia/nuxt',
        'pinia-plugin-persistedstate/nuxt',
        'vuetify-nuxt-module',
        '@nuxt/image',
        'dayjs-nuxt',
        'nuxt-lodash',
        'nuxt-zod-i18n',
        'nuxt-mdi',
        '@nuxtjs/sitemap',
        '@nuxtjs/seo',
        'nuxt-csurf',
        '@vite-pwa/nuxt',
        '@nuxtjs/html-validator',
        'nuxt-viewport',
        '@nuxtjs/device',
        '@dargmuesli/nuxt-cookie-control',
        '@nuxtjs/google-fonts',
        'nuxt-svgo',
        'nuxt-snackbar',
        'nuxt-marquee',
        'nuxt-particles'
    ],
    i18n: {
        baseUrl: process.env.SITE_URL,
        locales:
            [
                {
                    code: 'en',
                    language: 'en-US',
                    file: 'en.json',
                },
                {
                    code: 'zh-cn',
                    language: 'zh-cn',
                    file: 'zh-cn.json',
                },
            ],
        defaultLocale: 'zh-cn',
        strategy: 'no_prefix',
        detectBrowserLanguage: {
            useCookie: true,
            alwaysRedirect: true,
            cookieKey: process.env.LANGUAGE_COOKIE_KEY,
            cookieCrossOrigin: true,
            redirectOn: 'root'
        },
        experimental: {
            localeDetector: './i18n.ts'
        }
    },
    pinia: {
        storesDirs: ['./stores/**'],
        disableVuex: true,
    },
    piniaPluginPersistedstate: {
        key: '%id',
        storage: !process.env.SSR ? 'cookies' : 'localStorage', //开启ssr=ture后,只能使用cookies模式
        debug: process.env.NODE_ENV !== 'production',
    },
    sourcemap: {
        server: process.env.NODE_ENV !== 'production',
        client: process.env.NODE_ENV !== 'production'
    },
    googleFonts: {
        display: 'auto',
        families: {
            Roboto: true,
            Montserrat: true,
        },
        base64: true,
        fontsDir: './assets/fonts'
    },
    vuetify: {
        moduleOptions: {
            ssrClientHints: {
                prefersColorScheme: false,
                prefersColorSchemeOptions: {
                    useBrowserThemeOnly: true
                }
            }
        },
        vuetifyOptions: {
            labComponents: true,
            directives: true
        }
    },
    typescript: {
        strict: true,
    },
    runtimeConfig: {
        public: {
            serverHost: process.env.SERVER_HOST,
            clientCode: process.env.CLIENT_CODE,
            clientSecret: process.env.CLIENT_SECRET,
            languageCookieKey: process.env.LANGUAGE_COOKIE_KEY,
            serverMethod: process.env.SERVER_METHOD
        },
    },
    css: ['@mdi/font/css/materialdesignicons.css', '@vue-flow/core/dist/style.css', '@vue-flow/core/dist/theme-default.css', '@vue-flow/node-resizer/dist/style.css', '@vue-flow/minimap/dist/style.css', '@vue-flow/controls/dist/style.css'],
    image: {
        inject: true,
        quality: 100,
        dir: './assets/images'
    },
    dayjs: {
        locales: ['zh-cn', 'en'],
        plugins: ['relativeTime', 'utc', 'timezone'],
        defaultLocale: 'zh-cn',
        defaultTimezone: 'Asia/Shanghai',
    },
    ogImage: {enabled: process.env.NODE_ENV === 'production'},
    lodash: {
        prefix: 'useLodash',
        prefixSkip: ['string'],
        upperAfterPrefix: true,
        exclude: ['map'],
    },
    csurf: {
        https: process.env.NODE_ENV === 'production',
        cookieKey: 'csrf-token',
        cookie: {
            path: '/',
            httpOnly: process.env.NODE_ENV !== 'production',
            sameSite: 'strict',
            secure: process.env.NODE_ENV === 'production'
        },
        methodsToProtect: ['POST', 'PUT', 'DELETE'],
        encryptSecret: 'Wf9FnEYqZmR4JWV1x06w15fdzDb50g==',
        addCsrfTokenToEventCtx: true,
        headerName: 'csrf-token'
    },
    pwa: {},
    htmlValidator: {
        usePrettier: true,
        failOnError: true,
        ignore: [/\.(xml|rss|json)$/],
        options: {
            extends: [
                'html-validate:document',
                'html-validate:recommended',
                'html-validate:standard'
            ],
            rules: {
                //https://html-validate.org/rules/presets.html 配置
                'svg-focusable': 'off',
                'no-unknown-elements': 'error',
                'void-style': 'off',
                'no-trailing-whitespace': 'off',
                'require-sri': 'off',
                'attribute-boolean-style': 'off',
                'doctype-style': 'off',
                'no-inline-style': 'off',
                'text-content': 'off',
                'prefer-native-element': 'off',
                'no-redundant-role': 'off',
                'element-required-content': 'off',
                'element-required-attributes': 'off',
            }
        }
    },
    viewport: {
        breakpoints: {
            desktop: 1024,
            desktopMedium: 1280,
            desktopWide: 1600,
            mobile: 320,
            mobileMedium: 375,
            mobileWide: 425,
            tablet: 768,
        },
        cookie: {
            expires: 365, // 365 days
            name: 'viewport',
            path: '/',
            sameSite: 'Strict',
            secure: true,
        },
        defaultBreakpoints: {
            desktop: 'desktop',
            mobile: 'mobile',
            tablet: 'tablet',
        },
        fallbackBreakpoint: 'desktop',
        feature: 'maxWidth',
    },
    cookieControl: {},
    seo: {
        fallbackTitle: true,
        enabled: true,
        debug: process.env.NODE_ENV !== 'production'
    },
    site: {
        currentLocale: 'zh-cn',
        trailingSlash: process.env.NODE_ENV == 'production',
    },
    svgo: {
        autoImportPath: './assets/icons/',
        componentPrefix: 'svgo'
    },
    devServer: {
        port: 9001
    },
    snackbar: {
        top: true,
        center: true,
        duration: 3000
    },
    mdi: {
        defaultSize: '10em'
    }
})